var vm = new Vue({
    el: "#app",
    delimiters: ['[[', ']]'],
    data: {
        username: '',
        password: '',
        repassword: '',
        mobile:  '',
        error_username_msg: '',
        error_mobile_msg: '',
        allow: '',
        registerUrl: '',
        error_username: false,
        error_password: false,
        error_repassword: false,
        error_mobile: false,
        error_allow: false
    },
    methods: {
        check_username() {
            var re = /^[a-zA-Z0-9_-]{5,20}$/;
            if (re.test(this.username)) {
                this.error_username = false;
            } else {
                this.error_username_msg = '请输入 5-20 个字符的用户名';
                this.error_username = true;
            }
        },
        check_password() {
            var re = /^[a-zA-Z0-9_-]{5,20}$/;
            if (re.test(this.password)) {
                this.error_password = false;
            } else {
                this.error_password = true;
            }
        },
        check_repassword() {
            if (this.password === this.repassword) {
                this.error_repassword = false;
            } else {
                this.error_repassword = true;
            }
        },
        check_mobile() {
            var re = /^\d{11}$/;
            if (re.test(this.mobile)) {
                this.error_mobile = false;
            } else {
                this.error_mobile = true;
                this.error_mobile_msg = "请输入正确的手机号格式";
            }
        },
        check_allow() {
            this.allow = "true";
        },
        on_submit() {
            if (this.error_username === true || this.error_password === true || this.error_repassword === true || this.error_mobile === true || this.allow !== true) {
                window.event.returnValue = false;
            }
        }
    }
})